Course 4 - The Power of Statistics
Your team is nearing the midpoint of their user churn project. So far, you’ve completed a project proposal, and used Python to explore and analyze Waze’s user data. You’ve also used Python to create data visualizations. The next step is to use statistical methods to analyze and interpret your data.
You receive a new email from Sylvester Esperanza, your project manager. Sylvester tells your team about a new request from leadership: to analyze the relationship between mean amount of rides and device type. You also discover follow-up emails from three other team members: May Santner, Chidi Ga, and Harriet Hadzic. These emails discuss the details of the analysis. They would like a statistical analysis of ride data based on device type. In particular, leadership wants to know if there is a statistically significant difference in mean amount of rides between iPhone® users and Android™ users. A final email from Chidi includes your specific assignment: to conduct a two-sample hypothesis test (t-test) to analyze the difference in the mean amount of rides between iPhone users and Android users.
A notebook was structured and prepared to help you in this project. Please complete the following questions and prepare an executive summary.
In this activity, you will explore the data provided and conduct a hypothesis test.
The purpose of this project is to demostrate knowledge of how to conduct a two-sample hypothesis test.
The goal is to apply descriptive statistics and hypothesis testing in Python.
This activity has three parts:
Part 1: Imports and data loading
Part 2: Conduct hypothesis testing
How did computing descriptive statistics help you analyze your data?
How did you formulate your null hypothesis and alternative hypothesis?
Part 3: Communicate insights with stakeholders
What key business insight(s) emerged from your hypothesis test?
What business recommendations do you propose based on your results?
Follow the instructions and answer the questions below to complete the activity. Then, you will complete an Executive Summary using the questions listed on the PACE Strategy Document.
Be sure to complete this activity before moving on. The next course item will provide you with a completed exemplar to compare to your own work.

Throughout these project notebooks, you'll see references to the problem-solving framework PACE. The following notebook components are labeled with the respective PACE stage: Plan, Analyze, Construct, and Execute.

Consider the questions in your PACE Strategy Document and those below to craft your response:
==> ENTER YOUR RESPONSE HERE
Complete the following tasks to perform statistical analysis of your data:
Import packages and libraries needed to compute descriptive statistics and conduct a hypothesis test.
# Import any relevant packages or libraries
### YOUR CODE HERE ###
import pandas as pd
import numpy as np
Import the dataset.
Note: As shown in this cell, the dataset has been automatically loaded in for you. You do not need to download the .csv file, or provide more code, in order to access the dataset and proceed with this lab. Please continue with this activity by completing the following instructions.
# Load dataset into dataframe
df = pd.read_csv('waze_dataset.csv')


Consider the questions in your PACE Strategy Document and those below to craft your response:
==> ENTER YOUR RESPONSE HERE
Use descriptive statistics to conduct exploratory data analysis (EDA).
Note: In the dataset, device is a categorical variable with the labels iPhone and Android.
In order to perform this analysis, you must turn each label into an integer. The following code assigns a 1 for an iPhone user and a 2 for Android. It assigns this label back to the variable device_new.
Note: Creating a new variable is ideal so that you don't overwrite original data.
Create a dictionary called map_dictionary that contains the class labels ('Android' and 'iPhone') for keys and the values you want to convert them to (2 and 1) as values.
Create a new column called device_type that is a copy of the device column.
Use the map() method on the device_type series. Pass map_dictionary as its argument. Reassign the result back to the device_type series.
</br></br>
When you pass a dictionary to the Series.map() method, it will replace the data in the series where that data matches the dictionary's keys. The values that get imputed are the values of the dictionary.
Example:
df['column']
| column |
|---|
| A |
| B |
| A |
| B |
map_dictionary = {'A': 2, 'B': 1}
df['column'] = df['column'].map(map_dictionary)
df['column']
| column |
|---|
| 2 |
| 1 |
| 2 |
| 1 |
# 1. Create `map_dictionary`
### YOUR CODE HERE ###
map_dict = {'Android':2, 'iPhone':1}
# 2. Create new `device_type` column
### YOUR CODE HERE ###
df['device_type'] = df['device'].map(map_dict)
# 3. Map the new column to the dictionary
### YOUR CODE HERE ###
df.head()
You are interested in the relationship between device type and the number of drives. One approach is to look at the average number of drives for each device type. Calculate these averages.
### YOUR CODE HERE ###
df.groupby('device_type')['drives'].mean()
Based on the averages shown, it appears that drivers who use an iPhone device to interact with the application have a higher number of drives on average. However, this difference might arise from random sampling, rather than being a true difference in the number of drives. To assess whether the difference is statistically significant, you can conduct a hypothesis test.
Your goal is to conduct a two-sample t-test. Recall the steps for conducting a hypothesis test:
Note: This is a t-test for two independent samples. This is the appropriate test since the two groups are independent (Android users vs. iPhone users).
Recall the difference between the null hypothesis ($H_0$) and the alternative hypothesis ($H_A$).
Question: What are your hypotheses for this data project?
==> ENTER YOUR RESPONSE HERE
Next, choose 5% as the significance level and proceed with a two-sample t-test.
You can use the stats.ttest_ind() function to perform the test.
Technical note: The default for the argument equal_var in stats.ttest_ind() is True, which assumes population variances are equal. This equal variance assumption might not hold in practice (that is, there is no strong reason to assume that the two groups have the same variance); you can relax this assumption by setting equal_var to False, and stats.ttest_ind() will perform the unequal variances $t$-test (known as Welch's t-test). Refer to the scipy t-test documentation for more information.
drives column for iPhone users.drives column for Android users.# 1. Isolate the `drives` column for iPhone users.
### YOUR CODE HERE ###
from scipy import stats
iphone = df[df['device_type']==1] ['drives']
# 2. Isolate the `drives` column for Android users.
### YOUR CODE HERE ###
android = df[df['device_type']==2]['drives']
# 3. Perform the t-test
### YOUR CODE HERE ###
stats.ttest_ind(a=iphone, b=android, equal_var=False)
Question: Based on the p-value you got above, do you reject or fail to reject the null hypothesis?
==> ENTER YOUR RESPONSE HERE

Consider the questions in your PACE Strategy Document to reflect on the Execute stage.
Now that you've completed your hypothesis test, the next step is to share your findings with the Waze leadership team. Consider the following question as you prepare to write your executive summary:
==> ENTER YOUR RESPONSE HERE
Congratulations! You've completed this lab. However, you may not notice a green check mark next to this item on Coursera's platform. Please continue your progress regardless of the check mark. Just click on the "save" icon at the top of this notebook to ensure your work has been logged.